package logic

import (
	"context"
	"zc2/model/redis"

	"zc2/userrpc/internal/svc"
	"zc2/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikeGoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikeGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeGoodsListLogic {
	return &LikeGoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikeGoodsListLogic) LikeGoodsList(in *userrpc.LikeGoodsListRequest) (*userrpc.LikeGoodsListResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Client.ZRevRangeWithScores("likegoodslist", 0, 9)
	var list []*userrpc.LikeGoodsList
	for _, z := range scores.Val() {
		goodsList := userrpc.LikeGoodsList{
			Name: z.Member.(string),
			Like: int64(z.Score),
		}
		list = append(list, &goodsList)
	}
	return &userrpc.LikeGoodsListResponse{List: list}, nil
}
